﻿
/*
 * PsTFS is a set of PowerShell commands to manage and use Team Foundation Server. PowerShell 
 * effectiveness is combined with the power of TFS API to maximizes TFS capabilities.
 * 
 * Creator : Choulant Noham
 * Mail : choulant@gmail.com
 * Blog : http://choulant.blogspot.com
 * 
 */

using System;
using System.Management.Automation;
using Microsoft.TeamFoundation.Client;
using PsTFS.Methodes;
using PsTFS.Objects;

namespace PsTFS.Commandes.Add
{
    /// <summary>
    /// Ajout d'une branche
    /// </summary>
    [Cmdlet(VerbsCommon.Add, "Branch")]
    public class Add_Branch : PsCmdlet
    {
        /// <summary>
        /// Permet de lancer le processus de création de branche
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                WriteObject(Methode.AddBranche(Description, Source, Target, Context.Instance.Project.Name));
            }
            catch (Exception ex)
            {
                var err = ErrorRecord(ex, ErrorCategory.WriteError);
                ThrowTerminatingError(err);
            }
            finally
            {
                base.ProcessRecord();
            }
        }

        /// <summary>
        /// Fin du processus de création de branche
        /// </summary>
        protected override void EndProcessing()
        {
            Log.AddLog(null, "Add-Branch is end");
            base.EndProcessing();
        }

        /// <summary>
        /// Object contenant Team Foundation Server
        /// </summary>
        [Parameter(Position = 0)]
        public TfsTeamProjectCollection TFS
        {
            set { Context.Instance.TFS = value; }
        }

        /// <summary>
        /// Nom du projet
        /// </summary>
        [Parameter(Position = 1)]
        public string ProjectName
        {
            get { return Context.Instance.Project != null ? Context.Instance.Project.Name : String.Empty; }
            set { Context.Instance.SetProject(value); }
        }

        /// <summary>
        /// Path to the source branch
        /// </summary>
        [Parameter(Position = 2, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string Source { get; set; }

        /// <summary>
        /// Path to the destination branch
        /// </summary>
        [Parameter(Position = 3, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string Target { get; set; }

        /// <summary>
        /// Description pour la creation de la branche
        /// </summary>
        [Parameter(Position = 4, Mandatory = true)]
        [ValidateNotNullOrEmpty]
        public string Description { get; set; }
    }
}


